﻿using System;

//这里不能加命名空间，否则会和 UnityEngine.Debug 类冲突
public class Debug
{
    public static bool canLog = true;
    public static bool canLogWarning = true;
    public static bool canLogError = true;
    public static bool canLogToServer = true;

    public static void Log(object message)
    {
        if (!canLog) return;
#if UNITY_WEBGL
        UnityEngine.Debug.Log($"[{DateTime.Now.ToString("HH:mm:ss.fff")}] {message}");
#else
        UnityEngine.Debug.Log($"[{DateTime.Now.ToString("fff")}] {message}");
#endif
    }

    /// <summary>
    /// 可以点击日志定位到对象
    /// </summary>
    /// <param name="message">打印信息</param>
    /// <param name="context">目标对象</param>
    public static void Log(object message, UnityEngine.Object context)
    {
        if (!canLog) return;
#if UNITY_WEBGL
        UnityEngine.Debug.Log($"[{DateTime.Now.ToString("HH:mm:ss.fff")}] {message}", context);
#else
        UnityEngine.Debug.Log($"[{DateTime.Now.ToString("fff")}] {message}", context);
#endif
    }

    public static void LogWarning(object message, object context = null)
    {
        if (!canLogWarning) return;
#if UNITY_WEBGL
        UnityEngine.Debug.LogWarning($"[{DateTime.Now.ToString("HH:mm:ss.fff")}] {message}");
#else
        UnityEngine.Debug.LogWarning($"[{DateTime.Now.ToString("fff")}] {message}");
#endif
    }

    public static void LogError(object message, object context = null)
    {
        if (!canLogError) return;
#if UNITY_WEBGL
        UnityEngine.Debug.LogError($"[{DateTime.Now.ToString("HH:mm:ss.fff")}] {message}");
#else
        UnityEngine.Debug.LogError($"[{DateTime.Now.ToString("fff")}] {message}");
#endif
    }

    public static void Assert(object content)
    {
        LogError(content);
    }
    
    public static void Assert(bool condition, object content)
    {
        if (condition)
        {
            LogError(content);
        }
    }
    
    public static void AssertFormat(bool condition, string format, params object[] args)
    {
        if (condition)
        {
            //LogError(content);
        }
    }

    public static void Fail(string content)
    {
        LogError(content);
    }
}
